package com.cloud.test02;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * request作用域
 * 作用范围：当前请求中
 *      通过该对象可以在一个请求中传递数据，作用范围：在一次请求中有效，即服务器跳转有效。（请求转发时有效）
 *      //设置域对象内容
 *      req.setAttribute(String,Object);
 *      //获取域对象内容
 *      req.getAttribute(name:String);
 *      //删除域对象内容
 *
 * @author DELL
 */

@WebServlet(value = {"/RTest05", "/rtest05"})
public class RequestTest05 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("----------Servlet05----------");
        //设置域对象内容
        req.setAttribute("name","admin");
        req.setAttribute("age",18);
        List<String> list = new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        req.setAttribute("list",list);

        /*//请求转发到06
        req.getRequestDispatcher("rtest06").forward(req,resp);*/
        //请求转发到.jsp并通过域对象传输数据
        req.getRequestDispatcher("index.jsp").forward(req,resp);
    }
}
